import time

from selenium.webdriver.common.by import By
from common.common import driver

# 主页测试
class TestHomepage():
    url=""
    driver=""

    def __init__(self):
        self.driver=driver.driver
        self.url="http://127.0.0.1:58080/index.html"
        self.driver.get(self.url)

    # 板块跳转测试
    def plate(self):
        # 跳转java板块
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(2) > a").click()
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert text=="Java"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转C++板块
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(3) > a").click()
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert text=="C++"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转前端技术板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(4) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "前端技术"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转MySQL板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(5) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "MySQL"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转面试宝典板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(6) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "面试宝典"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转经验分享板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(7) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "经验分享"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转招聘信息板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(8) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "招聘信息"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转福利待遇板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(9) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "福利待遇"
        # 添加屏幕截图
        driver.getScreeShot()

        # 跳转灌水区板块
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(10) > a").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title").text
        assert text == "灌水区"
        # 添加屏幕截图
        driver.getScreeShot()

    # 退出登录
    def signout(self):
        # 点击主页右上角头像
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown > a").click()
        # 点击退出
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_logout").click()
        # 跳转登录页面
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR, "body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2").text
        assert text=="用户登录"
        # 添加屏幕截图
        driver.getScreeShot()


